//
//  PBOrderNameCell.m
//  PBHomeDemo
//
//  Created by Playboy on 2018/1/12.
//  Copyright © 2018年 tmkj. All rights reserved.
//

#import "PBOrderNameCell.h"

@interface PBOrderNameCell ()<UITextFieldDelegate>

@property (strong, nonatomic) IBOutlet UILabel *typeLabel;
@property (strong, nonatomic) IBOutlet UITextField *desTextField;

@end

@implementation PBOrderNameCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.desTextField.delegate = self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)refreshWithIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        self.typeLabel.text = @"姓名";
        self.desTextField.placeholder = @"姓名";
        self.desTextField.tag = 100;
        self.desTextField.keyboardType = UIKeyboardTypeDefault;
    }else if (indexPath.row == 1) {
        self.typeLabel.text = @"手机号";
        self.desTextField.placeholder = @"手机号";
        self.desTextField.tag = 101;
        self.desTextField.keyboardType = UIKeyboardTypeNumberPad;
    }
}

#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {

    if (self.delegate && [self.delegate respondsToSelector:@selector(inputWithValue:tag:)]) {
        [self.delegate inputWithValue:textField.text tag:textField.tag];
    }
    
    return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if ([string isEqualToString:@"\n"]){
        [self endEditing:YES];
        return NO;
    }
    return YES;
}

@end
